using System.Collections.Generic;
using System.Xml.Schema;
using Sixeyed.CodeGeneration.Metadata.Bases;
using Sixeyed.CodeGeneration.Metadata.Interfaces;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Interfaces;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Items;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Providers.Bases;

namespace Sixeyed.CodeGeneration.Metadata.Wsdl.Providers
{
    /// <summary>
    /// Provider for returning <see cref="Schema"/> metadata items
    /// </summary>
    /// <remarks>
    /// Provider shows all available schemas available at the WSDL endpoint.
    /// Schema's target namespace is used as the key for the metadata item.
    /// </remarks>
    public class SchemaProvider : WsdlProviderBase
    {
        /// <summary>
        /// Gets the provider name
        /// </summary>
        public override string Name
        {
            get { return "Schema Provider"; }
        }

        /// <summary>
        /// Gets the provider description
        /// </summary>
        public override string Description
        {
            get { return "Retrieves metadata representing an XML Schema"; }
        }

        /// <summary>
        /// Gets the name of the returned metadata item type
        /// </summary>
        public override string ItemTypeName
        {
            get { return "Schema"; }
        }

        /// <summary>
        /// Returns a list of available schemas
        /// </summary>
        /// <returns>List of schemas</returns>
        public override List<string> GetItemNames()
        {
            return this._source.GetSchemaNames();
        }

        /// <summary>
        /// Returns a populated metadata item
        /// </summary>
        /// <param name="itemKey">Target namespace of schema</param>
        /// <returns>Populated <see cref="Schema"/></returns>
        public override IMetadataItem GetItem(string itemKey)
        {
            Schema schema = this.CreateItem<Schema>(itemKey);
            XmlSchema xmlSchema = this._source.GetSchema(itemKey);
            schema.TypedItem = xmlSchema;
            return schema;
        }
    }
}
